﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;
using ProjectBase.Core.Web;

namespace ProjectBase.Mvc.Models
{
    /// <summary>
    ///     This model serves as the holder of the current user information.
    ///     Properties could (should) be filled in some of the AOP filters.
    ///     The best choice would be the AccessRights evaluating one.
    ///     MasterPage then can use these values for rendering.
    ///     (suggestion: for internet app it could be extended with logon for example)
    /// </summary>
    public class CurrentUserModel : CoreModel, ICurrentUserModel
    {
        #region members
        string _userName = string.Empty;
        #endregion members

        #region ICurrentUserModel Members
        /// <summary>
        ///     This property should contain the current (athenticated) user
        ///     Description (e.g. first and second name).
        ///     If not set, then returns UserLogin ?? string.Empty
        /// </summary>
        public virtual string UserName
        {
            get
            {
                if (_userName.IsEmpty())
                {
                    return UserLogin;
                }
                return _userName;
            }
            set { _userName = value; }
        }

        /// <summary>
        ///     This property should contain the current (athenticated) user unique identification
        ///     (e.g. login). This value is used only for rendering on UI.
        /// </summary>
        public virtual string UserLogin { get; set; }

        /// <summary>
        ///     If application provides some middle tier between user RoleProvider.Roles
        ///     and application business roles - provide the CurrentStateDescription and CurrentStateEntity.
        ///     Example of the CurrentStateDescription: 'Role', 'On behalf of' etc.
        /// </summary>
        public virtual string CurrentStateDescription { get; set; }

        /// <summary>
        ///     If application provides some middle tier between user RoleProvider.Roles
        ///     and application business roles - provide the CurrentStateDescription and CurrentStateEntity.
        ///     Example of the CurrentState: 'Administrator', 'Viewer', 'as JOHN' etc.
        ///     CurrentStateEntity must be IPersistent to provide ToDisplay() and the ID properties
        ///     which could be used for runtime changes
        /// </summary>
        public virtual object CurrentStateEntity { get; set; }

        /// <summary>
        ///     If application supports the middle tier for changing the user business role
        ///     (the one provided in the 'CurrentState' property)
        ///     provide this URL.
        ///     On MasterPage this could be used for generating the linkt to that action
        /// </summary>
        public virtual string ChangeStateUrl { get; set; }

        /// <summary>
        ///     when forms authentication is used, allowes to quickly Logout...
        /// </summary>
        public virtual string LogoutUrl { get; set; }
        #endregion
    }
}